package com.daona.infrastructure.tools;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

public class CodeGenerator {

    public static void main(String[] args) {
        generate();
    }

    private static void generate() {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/credit_app", "root", "123456")
                //FastAutoGenerator.create("jdbc:mysql://139.196.243.203:3306/investors", "root", "Gll2024admin2024")
                .globalConfig(builder -> builder
                        .author("bill.hu")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/daona-infrastructure/src/main/java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.daona.infrastructure.repository")
                        .moduleName("db")
                        .entity("entity")
                        .mapper("mapper")
                        //.service("service")
                        //.serviceImpl("service.impl")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, Paths.get(System.getProperty("user.dir")) + "/daona-infrastructure/src/main/resources/mapper"))
                        //.xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        //.addInclude(new String[]{"addresstypes"})
                        .entityBuilder()
                        .enableLombok()
                        .enableTableFieldAnnotation()
                        .mapperBuilder().enableMapperAnnotation()
                        .serviceBuilder().disable()
                        .controllerBuilder().disable()
                ).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
